﻿

package com.jxl.dnd.equipment
{
	import com.jxl.dnd.Attribute;
	
	
	public class ItemEffect
	{
		public static const ADJUST_SET:uint 			= 0;
		public static const ADJUST_ADD:uint 			= 1;
		public static const ADJUST_SUBTRACT:uint 		= 2;
		
		
		public var attribute:Attribute; // one of the Character.[Attribute Constant]
		public var adjustedValue:Number; // typically a positive or negative number
		public var adjustedType:uint; // either SET, ADD, SUBTRACT
		public var duration:Number; // in rounds, so duration = 5 is 5 rounds
		public var temporary:Boolean; // if temporary, removed at end of duration
		// or battle, whichever comes first
		
		
		public function ItemEffect(attribute:Attribute,
									adjustedValue:Number=0,
									adjustType:uint=0,
									duration:Number=0,
									temporary:Boolean=false):void
		{
			this.attribute			= attribute;
			this.adjustedValue		= adjustedValue;
			this.adjustedType		= adjustedType;
			this.duration			= duration;
			this.temporary			= temporary;
		}
		
		public function toXML():XML
		{
			var effectXML:XML = 
				<itemeffect>
					<attribute>{attribute}</attribute>
					<adjustedvalue>{adjustedValue}</adjustedvalue>
					<adjustedtype>{adjustedType}</adjustedtype>
					<duration>{duration}</duration>
					<temporary>{temporary}</temporary>
				</itemeffect>;
			return effectXML;
		}
		
		public function buildFromXML(xml:XML):void
		{
			attribute			= new Attribute(parseInt(xml.attribute));
			adjustedValue		= parseInt(xml.adjustedvalue);
			adjustedType		= parseInt(xml.adjustedtype);
			duration			= parseInt(xml.duration);
			temporary			= (xml.temporary == "true" || xml.temporary == "1") ? true : false;
		}
		
	}
}


